<?php
/**
 * Created by PhpStorm.
 * User: ZCY
 * Date: 2018/11/21
 * Time: 14:03
 */

require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
//建立一个连接通道，声明一个可以发送消息的队列hello
$connection = new AMQPStreamConnection('192.168.100.108', 5672, 'zcy', '196000');
$channel = $connection->channel();
$channel->queue_declare('task_queue', false, true, false, false);
$data = implode(' ', array_slice($argv, 1));
if(empty($data)) $data = "Hello World!";
$msg = new AMQPMessage($data,
    array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)
);

$channel->basic_publish($msg, '', 'task_queue');

echo " [x] Sent ", $data, "\n";

//关闭连接
$channel->close();
$connection->close();